package com.xcdh.trading.util;

import com.baomidou.mybatisplus.annotation.TableField;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ColumnTrUtil {

    public static Map<String,String> build(Class<?> clazz , ColumnTrItem trItem , String otherPrefix){
        Map<String, String> keyMap = buildColumnMap(clazz);
        for (Map.Entry<String, String> entry : keyMap.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            boolean exist = trItem.getColumns().contains(key);
            keyMap.put(key , String.format("%s.%s" ,exist ? trItem.getPrefix() : otherPrefix , value ));
        }
        return  keyMap ;
    }


    public static Map<String,String> buildColumnMap(Class<?> clazz){
        Field[] declaredFields = clazz.getDeclaredFields();
        Map<String,String> fieldColumnMap = new HashMap<>() ;
        for (Field field : declaredFields) {
            fieldColumnMap.put(field.getName() , field.getName()) ;
        }
        return fieldColumnMap ;
    }

}
